package com.zxm.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.zxm.pojo.UserBodyInfo;
import com.zxm.pojo.UserInfo;
import com.zxm.service.UserBodyInfoService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 张鑫铭
 * 运动建议推送
 */
@Controller
@RequestMapping("/advice")
public class AdviceController {
	@Reference
	UserBodyInfoService userBodyInfoService;
	//用户身体健康等级
	private static  String healthLevel1 ="您的身体非常健康，建议您继续保持"; 
	private static  String healthLevel2 ="您的身体状况还不错，也不要忘了锻炼哦"; 
	private static  String healthLevel3 ="您的身体健康不如意哦，建议您加强锻炼，有一个强壮的身体来迎接每一天"; 
	private static  String healthLevel4 ="根据您的身体状况，建议您每天勤锻炼，都吃水果蔬菜，多吃营养品，日积月累才会有一个好身体";
	//根据用户BMI指数来返回用户的建议信息
	@RequestMapping("/showAdvice")
	@ResponseBody
	public Map<String,String> advice (UserInfo userInfo){
		UserBodyInfo userBodyInfo=userBodyInfoService.getUserBodyInfoBMI(userInfo.getUsername());
		String  bodyLevel=userBodyInfo.getUserBmi();
		Map<String,String> map=new HashMap<>();
		Long level=Long.parseLong(bodyLevel);
		if(level <18.5){
			map.put("healthLevel4", healthLevel4);
			return map;
		}
		if(level>=18.5&&level<23.9) {
			map.put("healthLevel1", healthLevel1);
			return map;
		}
		if(level>24.0&&level<=27.9) {
			map.put("healthLevel2", healthLevel2);
			return map;
		}
		if(level>=28) {
			map.put("healthLevel3", healthLevel3);
			return map;
		}
		return map;
		
	}  
}
